<%
response.reset();
response.setContentType("application/octet-stream");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition","attachment;filename=\"trackerlist.xls\"" ); 
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"  
import="java.util.*,java.text.SimpleDateFormat,
com.brother.model.*,com.ibatis.common.util.PaginatedList
,com.brother.util.DateFormatter,com.brother.model.AlarmType,
java.util.*,
com.brother.model.*,com.ibatis.common.util.*,com.brother.util.Distance,com.brother.service.*,com.brother.util.MyPaginatedList"  pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ include file="international.jsp" %> 
<jsp:useBean id="trackerService" class="com.brother.service.TrackerService"></jsp:useBean>
<%
String action = request.getParameter("action");
String userName = request.getParameter("userName");
String trackerName = request.getParameter("trackerName");
String userTrackerId = request.getParameter("userTrackerId");
int start = Integer.parseInt(request.getParameter("start")==null?"0":request.getParameter("start"));
int limit = Integer.parseInt(request.getParameter("limit")==null?"20":request.getParameter("limit"));

if(userName != null && userName.startsWith("Select")){
	userName = null;
}
if(trackerName != null && trackerName.startsWith("Select")){
	trackerName = null;
}
if(userTrackerId != null && userTrackerId.startsWith("Select")){
	userTrackerId = null;
}

if(action != null && action.equalsIgnoreCase("del")){
	String[] trackerids = request.getParameterValues("trackerid");
	for(String trackerid: trackerids)
	trackerService.deleteTracker(trackerid);
	response.sendRedirect("trackerList.jsp");
	return;
}
com.brother.model.Customer c = (com.brother.model.Customer)session.getAttribute(com.brother.Constants.LOGIN_SESSTION_NAME);
List<Tracker> trackers =new ArrayList();

if(c != null){
	if(action != null && action.equalsIgnoreCase("search")){
		
		if(action.equalsIgnoreCase("page")){
			userName = (String)session.getAttribute("userName");
			trackerName = (String)session.getAttribute("trackerName");
			userTrackerId = (String)session.getAttribute("userTrackerId");
		}else{
			session.setAttribute("userName", userName);
			session.setAttribute("trackerName", trackerName);
			session.setAttribute("userTrackerId", userTrackerId);			
		}
		
	}
}else{
	return;
}
trackers = trackerService.findChildrenTracker(c.getUserid(), userName, trackerName, userTrackerId);




String pageNo = request.getParameter("pageNo");
if(pageNo == null || !pageNo.matches("^\\d*$")){
	pageNo = "0";
}

Iterator<Tracker> datas = trackers.iterator();


%>

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title><fmt:message key="report.title"/> - <fmt:message key="company.name"/></title>
<meta name="description" content="<fmt:message key="description.keyword"/>" />
</head>
<body>

<table  width="100%" cellpadding="5" cellspacing="0"  border="1">
		<thead>		
	<tr>
		<th width="100"><strong><fmt:message key="user.name"/></strong></th>
		<th width="180"><strong><fmt:message key="tracker.name"/></strong></th>
		<th width="180"><strong><fmt:message key="tracker.id"/></strong></th>
		<th width="280"><strong><fmt:message key="tracker.remark"/></strong></th>
	</tr>
</thead>

<%
int count = 0;

while(datas.hasNext()){
	Tracker tracker = datas.next();	
	count++;
	
	
%>

		<tr bordercolor="#cccccc">
			<td style=" font-size:11px;"><b><%=tracker.getUserName() %>&nbsp;</b></td>
			<td style=" font-size:11px;"><%=tracker.getTrackerName()%>&nbsp;</td>
			<td style=" font-size:11px;"><%=tracker.getUserTrackerId()%>&nbsp;</td>
			<td style=" font-size:11px;"><%=tracker.getRemark()%>&nbsp;</td>
		</tr>
 
<%} %>
	
		</table>



</body>
</html>
					  
<%
com.brother.database.DataBase.closeThreadConnection();
%>